package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class StudentManager  implements DaoInterface<Student>{
	private ArrayList<Student> arList;
	public StudentManager(){
		arList= new ArrayList<>();
	}
	public StudentManager(ArrayList<Student> arList) {
		super();
		this.arList = arList;
	}
/*	public void addStudent(Student std){
		arList.add(std);
	}
	public Student searchStd(Student std){
		if(arList.contains(std)){
			return arList.get(arList.indexOf(std));
		}else{
			return null;
		}
	}
	public void reStudent(Student std){
		//arList.set(arList.indexOf(std), std);
		Student temp= arList.get(arList.indexOf(std));
		temp.setStdNum(std.getStdNum());
		temp.setStdName(std.getStdName());
		temp.setKorScore(std.getKorScore());
		temp.setEngScore(std.getEngScore());
		temp.setMathscore(std.getMathscore());
		
	}
	public void delStudent(Student std){
		if(arList.contains(std)){//포함되어있다면 그값을 가져와서 삭제한다
			arList.remove(arList.indexOf(std));}
			else{
				System.out.println("해당 학생 정보 없음");
			}
		}
	public void prnList(){
		for(Student std:arList){
			System.out.println(std);
		}
	}*/
	public void prnHeader() {
		String header=String.format("%3s, %5s, %4s, %4s, %4s, %4s, %4.2s",
				"학번", "성명", "국어", "영어", "수학","총점","평균");
		System.out.println(header);
	}
	@Override
	public void additem(Student item) {
		arList.add(item);
		
	}
	@Override
	public Student searchitem(Student item) {
		if(arList.contains(item)){
			return arList.get(arList.indexOf(item));
		}else{
			return null;
		}
	}
	@Override
	public void reitem(Student item) {
		//arList.set(arList.indexOf(std), std);
		Student temp= arList.get(arList.indexOf(item));
		temp.setStdNum(item.getStdNum());
		temp.setStdName(item.getStdName());
		temp.setKorScore(item.getKorScore());
		temp.setEngScore(item.getEngScore());
		temp.setMathscore(item.getMathscore());
		
	}
	@Override
	public void delitem(Student item) {
		if(arList.contains(item)){//포함되어있다면 그값을 가져와서 삭제한다
			arList.remove(arList.indexOf(item));}
			else{
				System.out.println("해당 학생 정보 없음");
			}
	}
	@Override
	public void prnList() {
		for(Student item:arList){
			System.out.println(item);
		}
	}
	}

